package cn.zspt.vank.service.impl;


import cn.zspt.vank.domain.*;
import cn.zspt.vank.domain.dto.OrderQuery;
import cn.zspt.vank.mapper.OrderMapper;
import cn.zspt.vank.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Override
    public List<Dish> findDishByCategory(int categoryId){
        return orderMapper.findDishByCategory(categoryId);
    }

    @Override
    public List<Category> findAllCategory(){
        return orderMapper.findAllCategory();
    }

    @Override
    public List<User> findAllUser(){
        return orderMapper.findAllUser();
    }
    @Override
    public void createOrder(Order order){
        orderMapper.createOrder(order);
        for(OrderItem orderItem:order.getOrderItems()){
            orderItem.setOrderId(order.getOrderId());
            orderMapper.saveOrderItem(orderItem);
        }
    }

    @Override
    public List<Order> findOrderTodayByUser(int userId){
        return orderMapper.findOrderTodayByUser(userId);
    }


    @Override
    public List<Order> findOrderByQuery(OrderQuery orderQuery) {
        return orderMapper.findOrderByQuery(orderQuery);
    }

    @Override
    public void takeOrder(int orderId) {
        orderMapper.takeOrder(orderId);
    }

    @Override
    public List<OrderItem> findOrderItems(int orderId) {
        return orderMapper.findOrderItems(orderId) ;
    }

    @Override
    public void payOrder(int orderId) {
        orderMapper.payOrder(orderId);
    }

    @Override
    public void abortOrder(int orderId) {
        orderMapper.abortOrder(orderId);
    }

}
